package store.model;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * 商品分类
 */
public class Category {

    /**
     * 分类编号
     */
    private int no;

    /**
     * 分类名称
     */
    private String name;

    public Category(String name){
        this.name = name;
    }

    public Category(int id, String name){
        this.no = id;
        this.name = name;
    }

    public static class CategoryRecover implements Recover<Category> {

        @Override
        public List<Category> recover(ResultSet set) throws SQLException {
            List<Category> list = new ArrayList<>();
            while (set.next()) {
                list.add(new Category(set.getInt("no"),set.getString("name")));
            }
            return list;
        }
    }

    public int getNo() {
        return no;
    }

    public void setNo(int no) {
        this.no = no;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    @Override
    public String toString() {
        return "【商品分类】 " +
                "编号：" + no +
                ", 分类名称：" + name;
    }
}
